<script language="javascript" type="text/javascript" src="/assets/My97DatePicker/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript" src="/assets/libs/fastadmin-layer/dist/layer.js"></script>
<style>
    .g_p_type{
        display: none;
    }
    #suggestions{
        background-color: black;
        color: white;
    }
    #autoSuggestionsList{
        background-color: black;
        color: white;
    }
    .suggestionList li {
        margin: 0px 0px 0px 0px;
        padding: 3px;
        cursor: pointer;
    }
    .suggestionList li:hover {
        background-color: #659CD8;
    }
    #j1suggestions{
        background-color: black;
        color: white;
    }
    #j1autoSuggestionsList{
        background-color: black;
        color: white;
    }
    .j1suggestionList li {
        margin: 0px 0px 0px 0px;
        padding: 3px;
        cursor: pointer;
    }
    .j1suggestionList li:hover {
        background-color: #659CD8;
    }
</style>
<script language="JavaScript">
    function lookup(inputString) {
        cus=-1;
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#suggestions').hide();
        } else {
            $.post("/admin/command/getplace", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#suggestions').show();
                    $('#autoSuggestionsList').html(data);
                }
            });
        }
    } // lookup
    function aa (){
        if(document.activeElement.id!="inputString"){
            if(document.activeElement.id!="inputString1"){
                setTimeout("$('#suggestions').hide();", 200);
            }
        }
    }
    function fill(obj) {
        console.log($(obj).html()+"##########");
        $('#inputString').val($(obj).html());
        $("#pinfo").html($(obj).attr("pcontent"))
        $("#info_linkid").val($(obj).attr("placeid"))
        $("#startcityid").val($(obj).attr("placeid"))
        $("#info_title").val($(obj).attr("pname"))
        $("#startcity").val($(obj).attr("pname"))
        //setTimeout("aa()",200);
    }
    function fill1(thisValue) {
        setTimeout("aa()",200);
    }
    //全局定义 当前选择的li数组下标
    var cus=-1;
    function sitem(event,obj){
//获取所有选项li
        var liarr=$("#autoSuggestionsList").find("li")
        //向上
        if (event.keyCode == 38) {
            $("#inputString1").focus();
            if(-1>cus){
                cus=liarr.length-2;
            }
            cus--;
            $("#autoSuggestionsList").find("li").css("background-color","#252525");
            $(liarr[cus]).css("background-color","#659CD8");
            $("#inputString").val($(liarr[cus]).html())
            $("#inputString1").val($(liarr[cus]).html())
        }
        //向下
        if(event.keyCode == 40){
            $("#inputString1").focus();
            if(cus>liarr.length-2){
                cus=-1;
            }
            cus++;
            $("#autoSuggestionsList").find("li").css("background-color","#252525");
            $(liarr[cus]).css("background-color","#659CD8");
            $("#inputString").val($(liarr[cus]).html())
            $("#inputString1").val($(liarr[cus]).html())
        }
        //回车
        if(event.keyCode == 13){
            console.log($(liarr[cus]).attr("placeid")+"@@@@@@@@");
            $("#inputString").val($(liarr[cus]).html())
            $("#inputString1").val($(liarr[cus]).html())
            $("#pinfo").html($(liarr[cus]).attr("pcontent"))
            $("#info_linkid").val($(liarr[cus]).attr("placeid"))
            $("#startcityid").val($(liarr[cus]).attr("placeid"))
            $("#info_title").val($(liarr[cus]).attr("pname"))
            $("#startcity").val($(liarr[cus]).attr("pname"))
            //$('#suggestions').hide();
            $("#inputString").focus();
            cus=-1;
        }
    }
    /////////////////////////////////////////////////////////
    function j1lookup(inputString) {
        j1cus=-1;
        if(inputString.length == 0) {
            // Hide the suggestion box.
            $('#j1suggestions').hide();
        } else {
            $.post("/admin/command/j1getplace", {queryString: ""+inputString+""}, function(data){
                if(data.length >0) {
                    $('#j1suggestions').show();
                    $('#j1autoSuggestionsList').html(data);
                }
            });
        }
    } // lookup
    function j1aa (){
        if(document.activeElement.id!="j1inputString"){
            if(document.activeElement.id!="j1inputString1"){
                setTimeout("$('#j1suggestions').hide();", 200);
            }
        }
    }
    function j1fill(obj) {
        console.log($(obj).html()+"##########");
        $('#j1inputString').val($(obj).html());
        $("#j1pinfo").html($(obj).attr("pcontent"))
        $("#j1info_linkid").val($(obj).attr("placeid"))
        $("#endcityid").val($(obj).attr("placeid"))
        $("#j1info_title").val($(obj).attr("pname"))
        $("#endcity").val($(obj).attr("pname"))
        //$('#j1suggestions').hide();
        //setTimeout("aa()",200);
    }
    function j1fill1(thisValue) {
        setTimeout("j1aa()",200);
    }
    //全局定义 当前选择的li数组下标
    var j1cus=-1;
    function j1sitem(event,obj){
//获取所有选项li
        var liarr=$("#j1autoSuggestionsList").find("li")
        //向上
        if (event.keyCode == 38) {
            $("#j1inputString1").focus();
            if(-1>j1cus){
                j1cus=liarr.length-2;
            }
            j1cus--;
            $("#j1autoSuggestionsList").find("li").css("background-color","#252525");
            $(liarr[j1cus]).css("background-color","#659CD8");
            $("#j1inputString").val($(liarr[j1cus]).html())
            $("#j1inputString1").val($(liarr[j1cus]).html())
        }
        //向下
        if(event.keyCode == 40){
            $("#j1inputString1").focus();
            if(j1cus>liarr.length-2){
                j1cus=-1;
            }
            j1cus++;
            $("#j1autoSuggestionsList").find("li").css("background-color","#252525");
            $(liarr[j1cus]).css("background-color","#659CD8");
            $("#j1inputString").val($(liarr[j1cus]).html())
            $("#j1inputString1").val($(liarr[j1cus]).html())
        }
        //回车
        if(event.keyCode == 13){
            console.log($(liarr[j1cus]).attr("placeid")+"@@@@@@@@");
            $("#j1inputString").val($(liarr[j1cus]).html())
            $("#j1inputString1").val($(liarr[j1cus]).html())
            $("#pinfo").html($(liarr[j1cus]).attr("pcontent"))
            $("#info_linkid").val($(liarr[j1cus]).attr("placeid"))
            $("#endcityid").val($(liarr[j1cus]).attr("placeid"))
            $("#info_title").val($(liarr[j1cus]).attr("pname"))
            $("#endcity").val($(liarr[j1cus]).attr("pname"))
            $("#j1inputString").focus();
            j1cus=-1;
        }
    }
</script>
<div class="content">
<div class="panel panel-default panel-intro">
    <div class="panel-body">
        <div id="" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <div class="bootstrap-table">
                        <div class="fixed-table-toolbar">
                            <div class="bs-bars pull-left">
                                <div id="toolbar" class="toolbar" style="position: relative;">
                                 <a href="/admin/product/package_add?pid={$pid}&fid={$fid}&type=0" class="btn btn-success btn-add " title="添加"><i class="fa fa-plus"></i> 添加</a>
                                </div>
                            </div>
                           <form action="" method="post">
                                <table  class="table table-striped table-bordered table-hover table-nowrap" data-operate-edit="1" data-operate-del="1" width="100%" border="1">
                                    <thead>
                                    <tr>
                                        <th style=" text-align: center;vertical-align: middle;width:5%;" data-field="info_order" height="45">
                                            <div class="th-inner ">排序</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:4.5%;" data-field="id">
                                            <div class="th-inner ">ID</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:4.5%;" data-field="id">
                                            <div class="th-inner ">父级名称</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:15%;" data-field="title">
                                            <div class="th-inner ">显示标题</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:15%;" data-field="title">
                                            <div class="th-inner ">所属层级</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:5%;" data-field="title">
                                            <div class="th-inner ">选择类型</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:5%;" data-field="title">
                                            <div class="th-inner ">套餐最低价</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:5%;" data-field="title">
                                            <div class="th-inner ">套餐最低折扣</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width:6%;" data-field="status">
                                            <div class="th-inner ">状态</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                        <th style="text-align: center; vertical-align: middle;width: 20%;" data-field="operate">
                                            <div class="th-inner ">操作</div>
                                            <div class="fht-cell"></div>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody data-listidx="0">
                                    {volist name="list" id="vo"}
                                    <tr >
                                        <td style=" text-align: center; vertical-align: middle;">
                                                 <span>{$vo.pa_order}</span>
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {$vo.id}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {$vo.name}
                                        </td>
                                        <td style="text-align: left; vertical-align: middle; ">
                                            <?php if($vo['level']>0){echo "|".str_repeat('-', $vo['level']*8);} ?>
                                            {$vo.ptitle}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {$pptype[$vo['pptype']]}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {if condition="$vo.selecttype eq 1"}
                                            多选
                                            {elseif condition="$vo.selecttype eq 2"/}
                                            单选
                                            {/if}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {$vo.lowestprice}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {$vo.lowestdiscount}
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            <span dt_1="{$vo.id}"  onclick="changePackage(this); " {if condition="$vo.status eq 1"} class="btn btn-success" {else/} class="btn btn-danger"{/if}> {if condition="$vo.status eq 1"}正常{else/} 下线{/if}</span>
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; ">
                                            {if condition="$vo['pptype'] neq 2"}
                                            <a href="/admin/product/package_add?pid={$vo.p_id}&fid={$vo.id}&type={$vo['pptype']+1}" class="btn btn-success btn-edit btn-disabled" title="添加子节点"><i class="fa fa-plus"></i> 添加子节点</a>
                                            {/if}
                                            <a href="{:url('package_edit',array('id'=>$vo['id']))}" class="btn btn-success btn-edit btn-disabled" title="编辑"><i class="fa fa-pencil"></i> 修改</a>
                                            <a href="javascript:;" onclick="package('{$vo['id']}','{$pid}')" class="btn btn-success btn-del" title="删除"><i class="fa fa-trash"></i> 删除</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                           </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script>
    function changePackage(o){
        var id=$(o).attr("dt_1");
        $.ajax({
            type:"post",
            dataType:"json",
            data:{"id":id},
            url:"/admin/product/changePackage",
            success:function(data){
                if(data==1){
                    $(o).attr("class",'btn btn-danger');
                    $(o).text("下线");
                }else{
                    $(o).attr("class",'btn btn-success');
                    $(o).text("正常");
                }
            }
        });
    }
    //套餐 删除
    function package(id,pid){
        $.ajax({
            type:'post',
            dataType:'json',
            url:'/admin/product/package_del',
            data:{'id':id,'pid':pid},
            success:function(data){
                if(data.status==1){
                    alert(data.message);
                    location.reload();
                }else{
                    alert(data.message);
                }
            }
        });
    }
//向上移动
    function btnUp(id){
        $.ajax({
            type:'post',
            dataType:'json',
            url:"/admin/product/package_up",
            data:{'id':id},
            success:function(data){
                if(data.status==1){
                    location.reload();
                }else{
                    alert(data.message);
                }
            }
        });
    }
// 向下移动
    function btnDown(id){
        $.ajax({
            type:'post',
            dataType:'json',
            url:"/admin/product/package_down",
            data:{'id':id},
            success:function(data){
                if(data.status==1){
                    location.reload();
                }else{
                    alert(data.message);
                }
            }
        });
    }
</script>
